<?php
class My_EventVenueController extends MM_Controller_My_EventDetailAction
{	
	/**
	 * var
	 */
	private $evid = null;
	
	/**
	 * @var MM_Service_Admin_EventVenue
	 */
	private $serviceEV = null;
	
	/**
	 * 初始化
	 */
	public function init()
	{
		parent::init();
		$this->serviceEV = new MM_Service_Admin_EventVenue();
	}
	
	/**
	 * index
	 */
	public function indexAction()
	{
		$this->helper->setPageView($this->pageview, WEB_TITLE, "eventvenue", null);
	}
	
	/**
	 * page
	 */
	public function pageAction()
	{
		if ( !empty($this->httpdata['act']) && isset($this->httpdata['act']) ) {
			$dt = new Mediad2_Utility_Datatable($this->serviceEV);
			if(!isset($this->httpdata['ovar'])) {
				$this->httpdata['ovar'] = "addtime";
			}
			$where = null;
			if(isset($this->httpdata['eid'])) {
				$where = sprintf("eid = '%s'",$this->httpdata['eid']);
			}
			$dt->init($this->httpdata['act'], array("name"),$where);
			$dt->create();
			$dt->response();
		}
	}
	
	/**
	 * list event content
	 */
	public function listAction()
	{
		if ( ($this->uid<1) || ($this->eid<1) ) {
			$this->result = $this->returnResult(Mediad2_Model_Result::CODE_FAILURE,'Miss parameter: uid/eid');
		} else {
			$where = "eid = $this->eid";
			$order = "evid asc";
			$this->result = $this->serviceEV->fetchAll(null,null,$where,$order,true);
		}
		echo $this->encodeResult($this->result);
	}
	
	/**
	 * create event content
	 */
	public function createAction()
	{
		if ( ($this->uid<1) || ($this->eid<1)
    			|| !isset($this->httpdata['name']) || empty($this->httpdata['name']) ) {
    		$this->result = $this->returnResult(Mediad2_Model_Result::CODE_FAILURE,'Miss parameter: uid/name');
    	} else {
    		//封装model
    		$model = new MM_Model_EventVenue();
    		$model->setEid($this->eid);
    		$model->setName($this->httpdata['name']);
    		if (isset($this->httpdata['desc'])) $model->setDesc($this->httpdata['desc']);
    		if (isset($this->httpdata['url'])) $model->setUrl($this->httpdata['url']);
    		if (isset($this->httpdata['w'])) $model->setW($this->httpdata['w']);
    		if (isset($this->httpdata['h'])) $model->setH($this->httpdata['h']);
    		if (isset($this->httpdata['level'])) $model->setLevel($this->httpdata['level']);
    	
    		$this->result = $this->serviceEV->insert($model);
    	}
    	echo $this->encodeResult($this->result);
	}
	
	/**
	 * update event content
	 */
	public function updateAction()
	{
		if ( ($this->uid<1)
				|| !isset($this->httpdata['evid']) || empty($this->httpdata['evid']) ) {
			$this->result = $this->returnResult(Mediad2_Model_Result::CODE_FAILURE,'Miss parameter: uid/evid');
		} else {
			$evid = $this->httpdata['evid'];
			$this->result = $this->serviceEV->updateVenue($evid, $this->httpdata);
		}
		echo $this->encodeResult($this->result);
	}
	
	/**
	 * delete event content
	 */
	public function delAction()
	{
		if ( ($this->uid<1)
				|| !isset($this->httpdata['evid']) || empty($this->httpdata['evid']) ) {
			$this->result = $this->returnResult(Mediad2_Model_Result::CODE_FAILURE,'Miss parameter: uid/evid');
		} else {
			$evid = $this->httpdata['evid'];
			$this->result = $this->serviceEV->delete($evid);
		}
		echo $this->encodeResult($this->result);
	}
	
	/**
	 * get event content
	 */
	public function getAction()
	{
		if ( !isset($this->httpdata['evid']) || empty($this->httpdata['evid']) ) {
			$this->result = $this->returnResult(Mediad2_Model_Result::CODE_FAILURE,'Miss parameter: uid/evid');
		} else {
			$evid = $this->httpdata['evid'];
			$this->result = $this->serviceEV->fetchAll(null,null,"evid=$evid",null,true);
		}
		echo $this->encodeResult($this->result);
	}
}